<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>交易记录</p>
      <i class="fa fa-arrow-left home-icon" @click="$router.push('/Wallet')"></i>
    </header>

    <!-- 筛选条件 -->
    <div class="filter-section">

      <div class="filter-tabs">
        <div 
          v-for="tab in filterTabs" 
          :key="tab.value"
          class="filter-tab" 
          :class="{ active: activeFilter === tab.value }"
          @click="activeFilter = tab.value"
        >
          {{ tab.label }}
        </div>
      </div>
      
      <div class="date-filter">
        <div class="date-input" @click="showStartDatePicker = true">
          <i class="fa fa-calendar"></i>
          <span>{{ formatDateDisplay(startDate) }}</span>
        </div>
        <span class="date-separator">至</span>
        <div class="date-input" @click="showEndDatePicker = true">
          <i class="fa fa-calendar"></i>
          <span>{{ formatDateDisplay(endDate) }}</span>
        </div>
        <button class="filter-btn" @click="applyFilter">
          <i class="fa fa-filter"></i>
        </button>
      </div>

      <!-- 交易类型筛选 -->
      <div class="type-filter">
        <div 
          v-for="type in transactionTypes" 
          :key="type.value"
          class="type-tag" 
          :class="{ active: selectedTypes.includes(type.value) }"
          @click="toggleTransactionType(type.value)"
        >
          {{ type.label }}
        </div>
      </div>
    </div>

    <!-- 统计信息 -->
    <div class="stats-section">
      <div class="stat-card">
        <div class="stat-value income">¥{{ formatAmount(totalIncome) }}</div>
        <div class="stat-label">总收入</div>
      </div>
      <div class="stat-card">
        <div class="stat-value expense">¥{{ formatAmount(totalExpense) }}</div>
        <div class="stat-label">总支出</div>
      </div>
      <div class="stat-card">
        <div class="stat-value count">{{ totalCount }}</div>
        <div class="stat-label">交易笔数</div>
      </div>
    </div>

    <!-- 交易列表 -->
    <div class="transaction-list-section">
      <div class="section-header">
        <h3>交易明细</h3>
        <div class="sort-options">
          <select v-model="sortBy" @change="() => sortTransactions()">
            <option value="time">按时间</option>
            <option value="amount">按金额</option>
          </select>
          <select v-model="sortOrder" @change="() => sortTransactions()">
            <option value="desc">降序</option>
            <option value="asc">升序</option>
          </select>
        </div>
      </div>

      <div class="transaction-list">
        <div v-if="filteredTransactions.length === 0" class="empty-state">
          <i class="fa fa-receipt"></i>
          <p>暂无交易记录</p>
          <button class="btn-primary" @click="resetFilter">重置筛选条件</button>
        </div>

        <div v-else>
          <div 
            v-for="(transaction, index) in filteredTransactions" 
            :key="transaction.id"
            class="transaction-item"
            @click="showTransactionDetail(transaction)"
          >
            <div class="transaction-main">
              <div class="transaction-icon" :class="getTransactionTypeClass(transaction.txnType)">
                <i :class="getTransactionIcon(transaction.txnType)"></i>
              </div>
              <div class="transaction-info">
                <div class="transaction-title">{{ getTransactionTypeText(transaction.txnType) }}</div>
                <div class="transaction-note">{{ transaction.remark }}</div>
                <div class="transaction-time">{{ formatDateTime(transaction.createTime) }}</div>
              </div>
              <div class="transaction-amount" :class="getAmountClass(transaction)">
                {{ formatTransactionAmount(transaction) }}
              </div>
            </div>
            
          </div>
        </div>
      </div>

      <!-- 加载更多 -->
      <div v-if="hasMore && filteredTransactions.length > 0" class="load-more">
        <button @click="loadMore" :disabled="loading">
          <i class="fa fa-spinner fa-spin" v-if="loading"></i>
          {{ loading ? '加载中...' : '加载更多' }}
        </button>
      </div>
    </div>

    <!-- 交易详情模态框 -->
    <div v-if="showDetailModal" class="modal-overlay" @click="showDetailModal = false">
      <div class="modal-content detail-modal" @click.stop>
        <div class="modal-header">
          <h3>交易详情</h3>
          <i class="fa fa-times" @click="showDetailModal = false"></i>
        </div>
        <div class="modal-body">
          <div v-if="selectedTransaction" class="transaction-detail">
            <div class="detail-header">
              <div class="detail-icon" :class="getTransactionTypeClass(selectedTransaction.txnType)">
                <i :class="getTransactionIcon(selectedTransaction.txnType)"></i>
              </div>
              <div class="detail-amount" :class="getAmountClass(selectedTransaction)">
                {{ formatTransactionAmount(selectedTransaction) }}
              </div>
              <div class="detail-title">{{ getTransactionTypeText(selectedTransaction.txnType) }}</div>
            </div>
            
            <div class="detail-info">
              <div class="info-row">
                <span class="info-label">交易时间</span>
                <span class="info-value">{{ formatDateTime(selectedTransaction.createTime) }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">交易单号</span>
                <span class="info-value">{{ selectedTransaction.id }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">交易备注</span>
                <span class="info-value">{{ selectedTransaction.remark }}</span>
              </div>
              <div v-if="selectedTransaction.orderId" class="info-row">
                <span class="info-label">订单号</span>
                <span class="info-value">{{ selectedTransaction.orderId }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">交易金额</span>
                <span class="info-value">{{ formatAmount(selectedTransaction.aggregateAmount) }}元</span>
              </div>
              <div v-if="selectedTransaction.overdraft_amount > 0" class="info-row">
                <span class="info-label">透支金额</span>
                <span class="info-value">{{ formatAmount(selectedTransaction.overdraftAmount) }}元</span>
              </div>
              <div class="info-row">
                <span class="info-label">交易总额</span>
                <span class="info-value">{{ formatAmount(selectedTransaction.aggregateAmount) }}元</span>
              </div>
            </div>
            
            <div class="detail-actions" v-if="selectedTransaction.status === 'failed'">
              <button class="btn-retry" @click="retryTransaction(selectedTransaction)">
                <i class="fa fa-refresh"></i>
                重新尝试
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 日期选择器 -->
    <div v-if="showStartDatePicker" class="modal-overlay" @click="showStartDatePicker = false">
      <div class="modal-content date-picker-modal" @click.stop>
        <div class="modal-header">
          <h3>选择开始日期</h3>
          <i class="fa fa-times" @click="showStartDatePicker = false"></i>
        </div>
        <div class="modal-body">
          <input type="date" v-model="startDate" class="date-input-field" />
        </div>
        <div class="modal-footer">
          <button class="btn-cancel" @click="showStartDatePicker = false">取消</button>
          <button class="btn-confirm" @click="showStartDatePicker = false">确认</button>
        </div>
      </div>
    </div>

    <div v-if="showEndDatePicker" class="modal-overlay" @click="showEndDatePicker = false">
      <div class="modal-content date-picker-modal" @click.stop>
        <div class="modal-header">
          <h3>选择结束日期</h3>
          <i class="fa fa-times" @click="showEndDatePicker = false"></i>
        </div>
        <div class="modal-body">
          <input type="date" v-model="endDate" class="date-input-field" />
        </div>
        <div class="modal-footer">
          <button class="btn-cancel" @click="showEndDatePicker = false">取消</button>
          <button class="btn-confirm" @click="showEndDatePicker = false">确认</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TransactionHistory',
  data() {
    return {
      user: {},
      transactions: [],
      filteredTransactions: [],
      activeFilter: 'all', // all, today, week, month, year
      startDate: this.getDateDaysAgo(30), // 默认显示最近30天
      endDate: this.getCurrentDate(),
      selectedTypes: [],
      sortBy: 'time',
      sortOrder: 'desc',
      showStartDatePicker: false,
      showEndDatePicker: false,
      showDetailModal: false,
      selectedTransaction: null,
      loading: false,
      hasMore: true,
      currentPage: 1,
      pageSize: 20,
      
      filterTabs: [
        { label: '全部', value: 'all' },
        { label: '今天', value: 'today' },
        { label: '本周', value: 'week' },
        { label: '本月', value: 'month' },
        { label: '今年', value: 'year' }
      ],
      
      transactionTypes: [
        { label: '充值', value: 'recharge' },
        { label: '消费', value: 'pay' },
        { label: '转账', value: 'transfer' },
        { label: '提现', value: 'withdraw' },
        { label: '退款', value: 'refund' }
      ]
    }
  },
  
  computed: {
    totalIncome() {
      return this.filteredTransactions
        .filter(t => this.isIncomeTransaction(t))
        .reduce((sum, t) => sum + Math.abs(parseFloat(t.aggregateAmount)), 0)
    },
    
    totalExpense() {
      return this.filteredTransactions
        .filter(t => !this.isIncomeTransaction(t))
        .reduce((sum, t) => sum + Math.abs(parseFloat(t.aggregateAmount)), 0)
    },
    
    totalCount() {
      return this.filteredTransactions.length
    }
  },
  
  created() {
    //获取token
    this.token = localStorage.getItem('token');
    //获取user
    this.$axios.get(`/user`, {
      headers: {
        'Authorization': `Bearer ${this.token}`
      }
    }).then(response => {
      this.user = response.data.data;
      console.log("用户信息", this.user);
      this.getTransactions()
    }).catch(error => {
      console.error(error);
    });
  },
  
  methods: {
    goBack() {
      this.$router.push({ path: '/wallet' })
    },
    
    formatAmount(amount) {
      return parseFloat(amount).toFixed(2)
    },
    
    formatDateDisplay(dateString) {
      const date = new Date(dateString)
      return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`
    },
    
    formatDateTime(dateString) {
      const date = new Date(dateString)
      return `${date.getMonth() + 1}/${date.getDate()} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
    },
    
    formatDateGroup(dateString) {
      const date = new Date(dateString)
      const today = new Date()
      const yesterday = new Date(today)
      yesterday.setDate(yesterday.getDate() - 1)
      
      if (date.toDateString() === today.toDateString()) {
        return '今天'
      } else if (date.toDateString() === yesterday.toDateString()) {
        return '昨天'
      } else {
        return `${date.getMonth() + 1}月${date.getDate()}日`
      }
    },
    
    shouldShowDateHeader(index) {
      if (index === 0) return true
      
      const currentDate = new Date(this.filteredTransactions[index].createTime).toDateString()
      const prevDate = new Date(this.filteredTransactions[index - 1].createTime).toDateString()
      
      return currentDate !== prevDate
    },
    
    isIncomeTransaction(transaction) {
      return this.user.id == transaction.toId;
    },
    
    getTransactionTypeClass(type) {
      const classMap = {
        recharge: 'recharge',
        pay: 'payment',
        transfer: 'transfer',
        withdraw: 'withdraw',
        refund: 'refund'
      }
      return classMap[type] || 'default'
    },
    
    getTransactionIcon(type) {
      const iconMap = {
        recharge: 'fa fa-plus-circle',
        pay: 'fa fa-shopping-cart',
        transfer: 'fa fa-exchange-alt',
        withdraw: 'fa fa-minus-circle',
        refund: 'fa fa-undo'
      }
      return iconMap[type] || 'fa fa-exchange'
    },
    
    getTransactionTypeText(type) {
      const textMap = {
        recharge: '充值',
        pay: '消费',
        transfer: '转账',
        withdraw: '提现',
        refund: '退款'
      }
      return textMap[type] || '交易'
    },
    
    getAmountClass(transaction) {
      // 使用完整交易对象判断
      if (this.isIncomeTransaction(transaction)) {
        return 'positive';
      }
      return 'negative';
    },
    
    formatTransactionAmount(transaction) {
      const amount = parseFloat(transaction.aggregateAmount);
      const sign = this.isIncomeTransaction(transaction) ? '+' : '-';
      return `${sign}¥${Math.abs(amount).toFixed(2)}`;
    },
    
    toggleTransactionType(type) {
      const index = this.selectedTypes.indexOf(type)
      if (index > -1) {
        this.selectedTypes.splice(index, 1)
      } else {
        this.selectedTypes.push(type)
      }
      this.applyFilter()
    },
    
    applyFilter() {
      let filtered = [...this.transactions]
      
      // 按时间范围筛选
      filtered = filtered.filter(t => {
        const transactionDate = new Date(t.createTime)
        const start = new Date(this.startDate)
        const end = new Date(this.endDate)
        end.setHours(23, 59, 59, 999) // 包含结束日期全天
        
        return transactionDate >= start && transactionDate <= end
      })
      
      // 按交易类型筛选
      if (this.selectedTypes.length > 0) {
        filtered = filtered.filter(t => this.selectedTypes.includes(t.txnType))
      }
      
      // 按时间筛选
      const now = new Date()
      switch (this.activeFilter) {
        case 'today':
          const today = new Date(now.getFullYear(), now.getMonth(), now.getDate())
          filtered = filtered.filter(t => new Date(t.createTime) >= today)
          break
        case 'week':
          const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000)
          filtered = filtered.filter(t => new Date(t.createTime) >= weekAgo)
          break
        case 'month':
          const monthAgo = new Date(now.getFullYear(), now.getMonth(), 1)
          filtered = filtered.filter(t => new Date(t.createTime) >= monthAgo)
          break
        case 'year':
          const yearAgo = new Date(now.getFullYear(), 0, 1)
          filtered = filtered.filter(t => new Date(t.createTime) >= yearAgo)
          break
      }
      
      // 排序
      this.sortTransactions(filtered)
      this.filteredTransactions = filtered.slice(0, this.currentPage * this.pageSize)
      this.hasMore = filtered.length > this.filteredTransactions.length
    },
    
    sortTransactions(data = null) {
      const dataToSort = data || this.filteredTransactions
      
      dataToSort.sort((a, b) => {
        let aValue, bValue
        
        if (this.sortBy === 'time') {
          aValue = new Date(a.createTime).getTime()
          bValue = new Date(b.createTime).getTime()
        } else if (this.sortBy === 'amount') {
          aValue = Math.abs(parseFloat(a.aggregateAmount))
          bValue = Math.abs(parseFloat(b.aggregateAmount))
        }
        
        return this.sortOrder === 'desc' ? bValue - aValue : aValue - bValue
      })
      
      if (!data) {
        this.filteredTransactions = [...dataToSort]
      }
    },
    
    resetFilter() {
      this.activeFilter = 'all'
      this.startDate = this.getDateDaysAgo(30)
      this.endDate = this.getCurrentDate()
      this.selectedTypes = []
      this.sortBy = 'time'
      this.sortOrder = 'desc'
      this.applyFilter()
    },
    
    showTransactionDetail(transaction) {
      this.selectedTransaction = transaction
      this.showDetailModal = true
    },
    
    retryTransaction(transaction) {
      this.$confirm('确定要重新尝试此交易吗？', '确认重试', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 这里调用重试交易的API
        this.$message.success('已提交重试请求')
        this.showDetailModal = false
      })
    },
    
    loadMore() {
      this.loading = true
      // 模拟加载延迟
      setTimeout(() => {
        this.currentPage += 1
        this.applyFilter()
        this.loading = false
      }, 1000)
    },
    
    getCurrentDate() {
      return new Date().toISOString().split('T')[0]
    },
    
    getDateDaysAgo(days) {
      const date = new Date()
      date.setDate(date.getDate() - days)
      return date.toISOString().split('T')[0]
    },
    
    getTransactions() {
      //获取Transactions
      this.$axios.get('/wallet/transactions', {
        headers: {
          'Authorization': `Bearer ${this.token}`
        }
      }).then(response => {
        this.transactions = response.data
        // 按时间降序排列
        this.transactions.sort((a, b) => new Date(b.createTime) - new Date(a.createTime))
        this.applyFilter()
      }).catch(error => {
        console.error(error);
      });
    },
  }
}
</script>

<style scoped>
/****************** 总容器 ******************/
.wrapper {
  width: 100%;
  min-height: calc(100vh - 16vw);
  padding-bottom: 18vw;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

/****************** header部分 ******************/
.wrapper header {
  width: 100%;
  height: 12vw;
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  color: #fff;
  font-size: 4.8vw;
  position: relative;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 15px rgba(0, 151, 255, 0.3);
}
.wrapper header .home-icon {
  position: absolute;
  right: 4vw;
  top: 50%;
  transform: translateY(-50%);
  font-size: 5vw;
  color: white;
  cursor: pointer;
  padding: 2vw;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.wrapper header .home-icon:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-50%) scale(1.1);
}

/****************** 筛选区域 ******************/
.filter-section {
  width: calc(100% - 30px); 
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 3.5vw 2.5vw;
  margin-top: 12vw;
  border-radius: 0 0 20px 20px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.filter-tabs {
  display: flex;
  margin-bottom: 4vw;
  background: #f8fafc;
  border-radius: 12px;
  padding: 1vw;
  border: 1px solid #e2e8f0;
}

.filter-tab {
  flex: 1;
  text-align: center;
  padding: 3vw 2vw;
  font-size: 3.6vw;
  color: #64748b;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 8px;
  margin: 0 0.5vw;
  font-weight: 500;
}

.filter-tab.active {
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(0, 151, 255, 0.3);
  transform: translateY(-1px);
}

.date-filter {
  display: flex;
  align-items: center;
  margin-bottom: 4vw;
  gap: 2vw;
  background: white;
  padding: 3vw;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  justify-content: space-between; /* 添加这行 */
}

.date-input {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 3vw;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 3.5vw;
  color: #334155;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #f8fafc;
  font-weight: 500;
  min-width: 0; /* 添加这行 */
  justify-content: center; /* 添加这行 */
}

.date-input:hover {
  border-color: #0097FF;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 151, 255, 0.1);
}

.date-input i {
  margin-right: 2vw;
  color: #0097FF;
}

.date-separator {
  font-size: 3.5vw;
  color: #64748b;
  margin: 0 1vw; /* 修改这里，减少间距 */
  font-weight: 500;
  flex-shrink: 0; /* 添加这行 */
}

.filter-btn {
  padding: 3.5vw 4vw;
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 151, 255, 0.3);
  flex-shrink: 0; /* 添加这行 */
}

.filter-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 151, 255, 0.4);
}

.type-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 2.5vw;
  background: white;
  padding: 3vw;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.type-tag {
  padding: 2.5vw 4.5vw;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border: 1px solid #cbd5e1;
  border-radius: 25px;
  font-size: 3.2vw;
  color: #475569;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 500;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.type-tag.active {
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  color: white;
  border-color: #0097FF;
  box-shadow: 0 4px 12px rgba(0, 151, 255, 0.3);
  transform: translateY(-2px);
}

/****************** 统计信息 ******************/
.stats-section {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 3vw;
  padding: 5vw 4vw;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  margin: 4vw;
  border-radius: 20px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  z-index: 1;
  width: calc(100% - 16vw); /* 添加这行 */
  margin-left: auto;
  margin-right: auto;
}

.stats-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #0097FF, #0056b3, #0097FF);
  border-radius: 20px 20px 0 0;
}

.stat-card {
  text-align: center;
  padding: 4vw 2vw;
  transition: transform 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
}

.stat-value {
  font-size: 5.5vw;
  font-weight: 800;
  margin-bottom: 1.5vw;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-value.income {
  background: linear-gradient(135deg, #4CAF50, #45a049);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-value.expense {
  background: linear-gradient(135deg, #FF6B6B, #e55353);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-value.count {
  background: linear-gradient(135deg, #0097FF, #0056b3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  font-size: 3.2vw;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/****************** 交易列表部分 ******************/
.transaction-list-section {
  width: calc(100% - 8vw);
  margin-bottom: 14vw;
  padding: 0 4vw;
  position: relative;
  z-index: 2;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4vw;
  padding: 3vw 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
  border-radius: 15px;
  padding: 3vw 4vw;
  margin-top: 2vw;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

.section-header h3 {
  font-size: 4.8vw;
  color: #1e293b;
  margin: 0;
  font-weight: 700;
  background: linear-gradient(135deg, #1e293b, #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sort-options {
  display: flex;
  gap: 2.5vw;
  align-items: center;
}

.sort-options select {
  padding: 2.5vw 3.5vw;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 3.5vw;
  color: #475569;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.sort-options select:focus {
  border-color: #0097FF;
  box-shadow: 0 0 0 3px rgba(0, 151, 255, 0.1);
  outline: none;
}

.transaction-list {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  margin-top: 2vw;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15vw 4vw;
  color: #94a3b8;
  text-align: center;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

.empty-state i {
  font-size: 20vw;
  margin-bottom: 6vw;
  opacity: 0.6;
  color: #cbd5e1;
}

.empty-state p {
  font-size: 4.2vw;
  margin: 0 0 8vw;
  color: #64748b;
  font-weight: 500;
}

.btn-primary {
  padding: 4vw 10vw;
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 4vw;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 15px rgba(0, 151, 255, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 151, 255, 0.4);
}

.transaction-item {
  padding: 4.5vw;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  background: white;
  margin: 1vw 0;
  border-radius: 15px;
  border-left: 4px solid transparent;
}

.transaction-item:hover {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  transform: translateX(5px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.transaction-item:last-child {
  border-bottom: none;
}

.date-header {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  padding: 3vw 4vw;
  font-size: 3.8vw;
  color: white;
  font-weight: 700;
  text-align: center;
  z-index: 10;
  margin: 2vw 0;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 151, 255, 0.3);
}

.transaction-main {
  display: flex;
  align-items: center;
  position: relative;
}

.transaction-icon {
  width: 12vw;
  height: 12vw;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 4vw;
  font-size: 5vw;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease;
}

.transaction-icon:hover {
  transform: scale(1.1) rotate(10deg);
}

.transaction-icon.recharge { 
  background: linear-gradient(135deg, #4CAF50, #45a049);
}
.transaction-icon.payment { 
  background: linear-gradient(135deg, #FF9800, #f57c00);
}
.transaction-icon.transfer { 
  background: linear-gradient(135deg, #2196F3, #1976d2);
}
.transaction-icon.withdraw { 
  background: linear-gradient(135deg, #FF6B6B, #e53935);
}
.transaction-icon.refund { 
  background: linear-gradient(135deg, #9C27B0, #7b1fa2);
}
.transaction-icon.default { 
  background: linear-gradient(135deg, #607D8B, #455a64);
}

.transaction-info {
  flex: 1;
}

.transaction-title {
  font-size: 4.5vw;
  color: #1e293b;
  margin-bottom: 1.5vw;
  font-weight: 700;
}

.transaction-note {
  font-size: 3.8vw;
  color: #64748b;
  margin-bottom: 1.5vw;
  font-weight: 500;
}

.transaction-time {
  font-size: 3.5vw;
  color: #94a3b8;
  font-weight: 500;
}

.transaction-amount {
  font-size: 5vw;
  font-weight: 800;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.transaction-amount:hover {
  transform: scale(1.05);
}

.transaction-amount.positive { 
  background: linear-gradient(135deg, #4CAF50, #45a049);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.transaction-amount.negative { 
  background: linear-gradient(135deg, #FF6B6B, #e53935);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.transaction-status {
  position: absolute;
  top: 4vw;
  right: 4vw;
  font-size: 3.2vw;
  padding: 1.5vw 3vw;
  border-radius: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.transaction-status.success { 
  background: linear-gradient(135deg, #f0fff4, #c6f6d5);
  color: #22543d;
  border: 1px solid #9ae6b4;
}
.transaction-status.pending { 
  background: linear-gradient(135deg, #fffaf0, #fed7aa);
  color: #7b341e;
  border: 1px solid #fbd38d;
}
.transaction-status.failed { 
  background: linear-gradient(135deg, #fff5f5, #fed7d7);
  color: #742a2a;
  border: 1px solid #feb2b2;
}
.transaction-status.canceled { 
  background: linear-gradient(135deg, #f7fafc, #e2e8f0);
  color: #4a5568;
  border: 1px solid #cbd5e1;
}

/****************** 加载更多 ******************/
.load-more {
  text-align: center;
  padding: 8vw 4vw;
  background: transparent;
}

.load-more button {
  padding: 4vw 10vw;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  font-size: 4vw;
  color: #475569;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 600;
  width: 100%;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.load-more button:hover:not(:disabled) {
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  border-color: #0097FF;
  color: white;
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0, 151, 255, 0.3);
}

.load-more button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/****************** 模态框样式 ******************/
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 4vw;
  animation: overlayFadeIn 0.3s ease;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border-radius: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: modalSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(-30px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5vw 4vw;
  border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 20px 20px 0 0;
}

.modal-header h3 {
  font-size: 5vw;
  margin: 0;
  color: #1e293b;
  font-weight: 700;
  background: linear-gradient(135deg, #1e293b, #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-header i {
  font-size: 5.5vw;
  color: #64748b;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 2vw;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.modal-header i:hover {
  color: #ff4757;
  background: #fff5f5;
  transform: rotate(90deg);
}

.modal-body {
  width: calc(100% - 40px); /* 添加这行 */
  padding: 5vw 4vw;
}

.modal-footer {
  display: flex;
  padding: 4vw;
  border-top: 1px solid #e2e8f0;
  gap: 3vw;
  background: #f8fafc;
  border-radius: 0 0 20px 20px;
}

.btn-cancel, .btn-confirm {
  flex: 1;
  padding: 4vw;
  border: none;
  border-radius: 12px;
  font-size: 4.2vw;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-cancel {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  color: #64748b;
  border: 1px solid #cbd5e1;
}

.btn-cancel:hover {
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-confirm {
  background: linear-gradient(135deg, #0097FF 0%, #0056b3 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(0, 151, 255, 0.3);
}

.btn-confirm:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 151, 255, 0.4);
}

/****************** 交易详情模态框 ******************/
.detail-modal {
  max-width: 90%;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

.transaction-detail {
  text-align: center;
}

.detail-header {
  padding: 6vw 4vw;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 5vw;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 20px 20px 0 0;
}

.detail-icon {
  width: 18vw;
  height: 18vw;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 4vw;
  font-size: 7vw;
  color: white;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
  border: 3px solid white;
}

.detail-icon.recharge { 
  background: linear-gradient(135deg, #4CAF50, #45a049);
}
.detail-icon.payment { 
  background: linear-gradient(135deg, #FF9800, #f57c00);
}
.detail-icon.transfer { 
  background: linear-gradient(135deg, #2196F3, #1976d2);
}
.detail-icon.withdraw { 
  background: linear-gradient(135deg, #FF6B6B, #e53935);
}
.detail-icon.refund { 
  background: linear-gradient(135deg, #9C27B0, #7b1fa2);
}

.detail-amount {
  font-size: 9vw;
  font-weight: 900;
  margin-bottom: 3vw;
  text-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.detail-amount.positive { 
  background: linear-gradient(135deg, #4CAF50, #45a049);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.detail-amount.negative { 
  background: linear-gradient(135deg, #FF6B6B, #e53935);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.detail-title {
  font-size: 5vw;
  color: #1e293b;
  margin-bottom: 3vw;
  font-weight: 700;
}

.detail-status {
  display: inline-block;
  padding: 2vw 5vw;
  border-radius: 15px;
  font-size: 3.8vw;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.detail-status.success { 
  background: linear-gradient(135deg, #f0fff4, #9ae6b4);
  color: #22543d;
  border: 2px solid #48bb78;
}
.detail-status.pending { 
  background: linear-gradient(135deg, #fffaf0, #fbd38d);
  color: #7b341e;
  border: 2px solid #ed8936;
}
.detail-status.failed { 
  background: linear-gradient(135deg, #fff5f5, #feb2b2);
  color: #742a2a;
  border: 2px solid #f56565;
}

.detail-info {
  text-align: left;
  margin-bottom: 5vw;
  background: white;
  padding: 4vw;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4vw 0;
  border-bottom: 1px solid #f1f5f9;
  transition: background-color 0.3s ease;
}

.info-row:hover {
  background: #f8fafc;
  border-radius: 8px;
  padding: 4vw 3vw;
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  font-size: 4vw;
  color: #64748b;
  font-weight: 600;
}

.info-value {
  font-size: 4vw;
  color: #1e293b;
  font-weight: 700;
  text-align: right;
  max-width: 60%;
  word-break: break-all;
}

.detail-actions {
  padding-top: 5vw;
  border-top: 1px solid #e2e8f0;
}

.btn-retry {
  width: 100%;
  padding: 4.5vw;
  background: linear-gradient(135deg, #FF6B6B 0%, #e53935 100%);
  color: white;
  border: none;
  border-radius: 15px;
  font-size: 4.5vw;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-retry:hover {
  background: linear-gradient(135deg, #e53935 0%, #c62828 100%);
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(255, 107, 107, 0.4);
}

.btn-retry i {
  margin-right: 3vw;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/****************** 日期选择器模态框 ******************/
.date-picker-modal {
  max-width: 80%;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

.date-input-field {
  width: 100%;
  padding: 5vw;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 4.5vw;
  text-align: center;
  font-weight: 600;
  color: #1e293b;
  transition: all 0.3s ease;
  background: white;
}

.date-input-field:focus {
  border-color: #0097FF;
  box-shadow: 0 0 0 3px rgba(0, 151, 255, 0.1);
  outline: none;
  transform: scale(1.02);
}


/****************** 响应式设计 ******************/
@media (min-width: 768px) {
  .wrapper {
    max-width: 500px;
    margin: 0 auto;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.1);
    min-height: 100vh;
    padding-bottom: 80px;
  }
  
  .wrapper header {
    height: 60px;
    border-radius: 0;
  }
  
  .wrapper header p {
    font-size: 20px;
  }
  
  .filter-section {
    padding: 20px 15px;
    margin-top: 60px;
    border-radius: 0 0 25px 25px;
  }
  
  .filter-tab {
    padding: 12px 8px;
    font-size: 14px;
  }
  
  .date-input {
    padding: 12px;
    font-size: 14px;
  }

  
  .date-separator {
    margin: 0 8px; /* 修改这里 */
    flex-shrink: 0; /* 添加这行 */
  }
  .date-filter {
    justify-content: space-between; /* 添加这行 */
  }
  
  .filter-btn {
    padding: 12px 15px;
  }
  .date-filter {
    justify-content: space-between; /* 添加这行 */
  }

  
  .type-tag {
    padding: 8px 16px;
    font-size: 12px;
  }
  
  .stats-section {
    padding: 25px 20px;
    gap: 15px;
    margin: 20px;
    border-radius: 25px;
    
  }
  
  .stat-card {
    padding: 15px 8px;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .stat-label {
    font-size: 12px;
  }
  
  .transaction-list-section {
    padding: 0 20px;
    width: calc(100% - 40px); /* 添加这行 */
  }
  
  .section-header h3 {
    font-size: 20px;
  }
  
  .sort-options select {
    padding: 10px 15px;
    font-size: 14px;
  }
  
  .empty-state {
    padding: 80px 20px;
  }
  
  .empty-state i {
    font-size: 80px;
  }
  
  .empty-state p {
    font-size: 16px;
  }
  
  .btn-primary {
    padding: 15px 30px;
    font-size: 14px;
  }
  
  .transaction-item {
    padding: 20px;
    margin: 5px 0;
  }
  
  .date-header {
    padding: 12px 20px;
    font-size: 16px;
    margin: 10px 0;
  }
  .date-input {
    min-width: 0; /* 添加这行 */
    justify-content: center; /* 添加这行 */
  }
  
  .transaction-icon {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
  
  .transaction-title {
    font-size: 16px;
  }
  
  .transaction-note {
    font-size: 14px;
  }
  
  .transaction-time {
    font-size: 12px;
  }
  
  .transaction-amount {
    font-size: 18px;
  }
  
  .transaction-status {
    top: 20px;
    right: 20px;
    font-size: 12px;
    padding: 6px 12px;
  }
  
  .load-more {
    padding: 30px 20px;
  }
  
  .load-more button {
    padding: 15px 30px;
    font-size: 14px;
  }
  
  .modal-header {
    padding: 25px 20px;
  }
  
  .modal-header h3 {
    font-size: 20px;
  }
  
  .modal-header i {
    font-size: 24px;
    padding: 8px;
  }
  
  .modal-body {
    padding: 25px 20px;
  }
  
  .modal-footer {
    padding: 20px;
    gap: 15px;
  }
  
  .btn-cancel, .btn-confirm {
    padding: 15px;
    font-size: 14px;
  }
  
  .detail-icon {
    width: 80px;
    height: 80px;
    font-size: 32px;
  }
  
  .detail-amount {
    font-size: 42px;
  }
  
  .detail-title {
    font-size: 20px;
  }
  
  .detail-status {
    padding: 8px 20px;
    font-size: 14px;
  }
  
  .info-row {
    padding: 15px 0;
  }
  
  .info-label, .info-value {
    font-size: 14px;
  }
  
  .btn-retry {
    padding: 15px;
    font-size: 14px;
  }
  
  .date-input-field {
    padding: 15px;
    font-size: 16px;
  }
  
  .bottom-nav {
    height: 80px;
    padding: 0 10px;
  }
  
}
</style>